package org.jiangnantaste.util;

import java.io.FileInputStream;
import java.io.IOException;

import android.util.Base64;

public class ImageHelper {

	public static String encode(byte[] bytes) {		
		return Base64.encodeToString(bytes,Base64.DEFAULT);
	}

	public static byte[] decode(String encodeStr) throws IOException {
		byte[] bt = null;
		bt = Base64.decode(encodeStr.getBytes(),Base64.DEFAULT);
		return bt;
	}

	public static byte[] connectBytes(byte[] front, byte[] after) {
		byte[] result = new byte[front.length + after.length];
		System.arraycopy(front, 0, result, 0, after.length);
		System.arraycopy(after, 0, result, front.length, after.length);
		return result;
	}

	public static String encodeImage(String imgUrl) throws IOException {
		FileInputStream fis = new FileInputStream(imgUrl);
		byte[] rs = new byte[fis.available()];
		fis.read(rs);
		fis.close();
		return encode(rs);
	}

	public static void main(String[] args) {
		String str;
		try {
			str = encodeImage("E:/Jerry/MyProj/PictureDemo/Jellyfish.jpg");
			System.out.println(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}